package exercise;

/**
 * @author shhjiang_001
 * @create 2020-07-15 20:43
 */
public class Solution0715 {
    public boolean isSubsequence(String s, String t) {
        // t长 s短
        char[] s1 = s.toCharArray();
        char[] s2 = t.toCharArray();
        int m = s1.length;
        int n = s2.length;
        int[][] dp = new int[m+1][n+1];
        for(int i = 1;i <= m;i++ ){
            for(int j = 1;j <= n;j++){
                if(s1[i-1] == s2[j-1]){
                    dp[i][j] = dp[i-1][j-1]+1;
                }else{
                    dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        if(dp[m][n] == m) return true;
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new Solution0715().isSubsequence("abc", "ahbgdc"));
        System.out.println(new Solution0715().isSubsequence("axc", "ahbgdc"));
    }
}
